-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(index): support adding index widget with initial UI state #4359
Conversation
in Vue InstantSearch server side rendering we call .addWidgets in hydrate, and otherwise this would cause an extra search. If we do keep this search then uiState which gets modified in the index widget needs to be changed.
E2E test failure seems to be a fluke (cc @yannickcr), locally the URL updates as expected in those scenarios |
Co-authored-by: Nuno Maduro <enunomaduro@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me. The PR is not too big.
Let me know if you need me to test anything or take a closer look at any part.
The e2e test seems to actually catch a bug; if a refinement is set again to the default value of the widget (usually nothing) the previous value for uiState is kept by the widget. This is expected on first render, but not later. |
The problem is related to this line Before this pull request, every change to the helper, will erase the uiState which is "still there", since it was reduced from an empty object. This was causing issues in Vue InstantSearch, since every widget added on server side erased the initialUiState (except the first widget to be mounted). The solution I saw was to base the new state of the existing state. The issue that pops up because of this is that when a widget refines, and later goes back to its default / unrefined state, all widgets have a guard that check "if not refined, return uiState", and thus they keep the previously refined state in the URL & uiState. A change I can imagine is in all widgets themselves removing that condition and returning a uiState with explicitly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
canceling approval until the bug is fixed.
src/widgets/index/index.ts
Outdated
{ | ||
state, | ||
isPageReset, | ||
_isFromAddWidget, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1) Instead of saying where it's from, what about saying what it does? (similarly to isPageReset
). This name looses sense suddenly if we were to reuse it somewhere else. A suggestion: _shouldInheritUiState
.
(2) To make it more testable and easier to think about, I would rather pass the baseUiState
object here, instead of a boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, I've changed it to _uiState
, where we pass the local ui state in this case
* feat(ssr): support multi index * WIP: update nuxt example with new API * different option * Revert "different option" This reverts commit f37fa7e. * remove debug leak * hydrate main index & use in force render * don't init in force render, because addWidget does it alreayd * fixes, ref: algolia/instantsearch#4359 * outdated note * initial next version of ssr todo: tests * more realistic instantsearch integration test * update widget mixin tests based on main index change * move stuff slightly * consistency in test * initial server root tests * commit the patch for now * commit patch * fix: wip * have a more real test * update tests * well discussed test cases & small tweaks * use test utility * actualize bundlesize * update examples * clean up example * remove lint error * suppress another lint * more patches for demo * commit paches * make dumb lint error disappear * fix flaky jest tests * test * update deps * ecom example fix * Update src/util/createServerRootMixin.js Co-authored-by: Eunjae Lee <eunjae.lee@algolia.com> * chore(deps): update e2e tests (#784) * chore(deps): update e2e tests * modern node * ci(circle): update node * ci(examples): use working version of core-js * chore(netlify): remove node modules * chore(ssr): avoid JSON cost * chore(ssr): don't resolve unused things * clean todos * fix typo * change comments Co-authored-by: Vaillant Samuel <samuel.vllnt@gmail.com> Co-authored-by: Eunjae Lee <eunjae.lee@algolia.com>
* feat(ssr): support multi index * WIP: update nuxt example with new API * different option * Revert "different option" This reverts commit f37fa7e. * remove debug leak * hydrate main index & use in force render * don't init in force render, because addWidget does it alreayd * fixes, ref: algolia/instantsearch#4359 * outdated note * initial next version of ssr todo: tests * more realistic instantsearch integration test * update widget mixin tests based on main index change * move stuff slightly * consistency in test * initial server root tests * commit the patch for now * commit patch * fix: wip * have a more real test * update tests * well discussed test cases & small tweaks * use test utility * actualize bundlesize * update examples * clean up example * remove lint error * suppress another lint * more patches for demo * commit paches * make dumb lint error disappear * fix flaky jest tests * test * update deps * ecom example fix * Update src/util/createServerRootMixin.js Co-authored-by: Eunjae Lee <eunjae.lee@algolia.com> * chore(deps): update e2e tests (#784) * chore(deps): update e2e tests * modern node * ci(circle): update node * ci(examples): use working version of core-js * chore(netlify): remove node modules * chore(ssr): avoid JSON cost * chore(ssr): don't resolve unused things * clean todos * fix typo * change comments Co-authored-by: Vaillant Samuel <samuel.vllnt@gmail.com> Co-authored-by: Eunjae Lee <eunjae.lee@algolia.com>
…arch#764) * feat(ssr): support multi index * WIP: update nuxt example with new API * different option * Revert "different option" This reverts commit f37fa7e626be09af6c31fe3cf4bd310967319aef. * remove debug leak * hydrate main index & use in force render * don't init in force render, because addWidget does it alreayd * fixes, ref: #4359 * outdated note * initial next version of ssr todo: tests * more realistic instantsearch integration test * update widget mixin tests based on main index change * move stuff slightly * consistency in test * initial server root tests * commit the patch for now * commit patch * fix: wip * have a more real test * update tests * well discussed test cases & small tweaks * use test utility * actualize bundlesize * update examples * clean up example * remove lint error * suppress another lint * more patches for demo * commit paches * make dumb lint error disappear * fix flaky jest tests * test * update deps * ecom example fix * Update src/util/createServerRootMixin.js Co-authored-by: Eunjae Lee <eunjae.lee@algolia.com> * chore(deps): update e2e tests (algolia/vue-instantsearch#784) * chore(deps): update e2e tests * modern node * ci(circle): update node * ci(examples): use working version of core-js * chore(netlify): remove node modules * chore(ssr): avoid JSON cost * chore(ssr): don't resolve unused things * clean todos * fix typo * change comments Co-authored-by: Vaillant Samuel <samuel.vllnt@gmail.com> Co-authored-by: Eunjae Lee <eunjae.lee@algolia.com>
Sorry for this larger pull request, if it proves too complicated for a single PR, we can split this up in three smaller PRs
since every added widget calls scheduleSearch if
init
has happened, this used to do a search, even beforestart
was called, and thus with not yet the correct statee.g. initialUiState contains a few widgets, if you mount those one by one, after
init
on its index, each widget would cause a change event on the helper, which used to erase non-valid state, since it starts from an empty ui state. This is now fixed by using the previous local ui state as base, but a special provision forisPageReset
It's okay to do
results.hits = ...
inside connectHits, since that overrides just the value onSearchResults
, however if we mutate within the inner hits, we are actually mutating_rawResults
, which isn't what we want to achieve for server side rendering, since_rawResults
gets serialised.Further changes are just minor for tests
How to test this?
Two options: